<!doctype html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title>钢链网-发票查询</title>
	<link rel="stylesheet" href="/resource/css/gl_index.css">
	<link rel="stylesheet" href="/resource/css/gl_user.css">
	<link rel="stylesheet" href="/resource/css/gl_showBo.css">
	<link rel="stylesheet" href="/resource/css/datepicker.css">

	<script src="/resource/js/jquery-1.11.3.min.js"></script>
	<script src="/resource/js/gl_index.js"></script>
	<script src="/resource/js/gl_showBo.js"></script>
	<script src="/resource/js/bootstrap-datepicker.js"></script>
	<script>
		$(function(){
			//日历
			var checkin = $('#dpd1').datepicker().on('changeDate', function(ev) {

				var newDate = new Date(ev.date);
				newDate.setDate(newDate.getDate() + 1);
				checkout.setValue(newDate);

				checkin.hide();
				$('#dpd2')[0].focus();
			}).data('datepicker');

			var checkout = $('#dpd2').datepicker({
				onRender: function(date) {
					return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
				}
			}).on('changeDate', function(ev) {
				checkout.hide();
			}).data('datepicker');
			//开票
			$('.billing').click(function () {
				var order_id = $(this).attr('order_id');
				$('.btn-billing').attr('order_id',order_id);
			});
		    $('.popup-billing input.form-control').after('<span></span>');
		    $('.popup-billing input.form-control').blur(function(){
		    	if(!$(this).val()){
		    		$(this).siblings('span').show().html('不能为空');
		    	}else{
		    		$(this).siblings('span').hide();
		    	}
		    });
		    $('.btn-billing').click(function(){
		    	var billing = [];
				var order_id = $(this).attr('order_id');
		    	for (var i = 0; i < $('.popup-billing input.form-control').length; i++) {
		    		if(!$('.popup-billing input.form-control').eq(i).val()){
			    		$('.popup-billing input.form-control').eq(i).focus().siblings('span').show().html('不能为空');
			    		return false;
			    	}else{
			    		billing.push($('.popup-billing input.form-control').eq(i).val());
			    	}
		    	};
				console.log(billing);
				console.log(order_id);
		    	$('.popup-billing').hide();
       			$('.popup').hide();
				$.ajax({
					url : '/add_invoice',
					type : "POST",
					data : {order_id:order_id,title:billing[0],address:billing[1],addressee:billing[2],phone:billing[3]},
					dataType : "json",
					cache:"false",
					timeout:30000,
					success : function(json) {
						Showbo.Msg.nameauth('<img src="/resource/img/gl_show_succ.png" style="margin-top:20px;"><div style="font-size:24px;">已确认开票</div><div style="margin-bottom:25px;line-height:38px;font-size:14px;color:#656464;">开票完成后，我们会尽快将发票寄到您的手中</div>',function(){
							location=location
						});
					}
				});
		    });
		    // 公司抬头
		    $('.all-company').click(function(){
		    	var $this = $(this);
		    	query($this);
		    });
		    $('.body-all ul li a').click(function(){
		    	$(this).parents('li').addClass('active').siblings().removeClass('active');
		    	$(this).parents('.body-all').siblings('.head-info').html($(this).html());
				var start_time = $('#start_time').val();
				var end_time = $('#end_time').val();
				var all_company = $('.all-company .head-info').html();
				var invoice_status = $('.invoice-status li.active').attr('rel');
				var str = "";

				$.ajax({
					url:"/select_invoice_ajax",
					type : "POST",
					data:{start_time:start_time,end_time:end_time,title:all_company,status:invoice_status},
					dataType : "json",
					cache:"false",
					timeout:30000,
					success : function(json) {
						$.each(json,function(index,arr){
							str += "<tr><td><div>"+arr.order_sn+"</div></td>";
							str += "<td><div>"+arr.title+"</div></td>";
							str += "<td><div>"+arr.created+"</div></td>";
							str += "<td><div>"+arr.amount+"</div></td>";
							str += "<td><div>"+arr.order_time+"</div></td><td>";
							if(arr.status == 0){
								str += "<div class=\"invoice-no\"><div class=\"left\">未开票</div><a href=\"javascript:;\" order_id="+arr.order_id+" class=\"billing\">立即开票</a></div>";
							}else if(arr.status == 1){
								str += "<div class=\"invoice-in\">开票中</div>";
							}else if(arr.status == 2){
								str += "<div class=\"invoice-yes\">已开票</div>";
							}
							str += "</td></tr>";
							console.log(arr);
						});
						$('.invoice .table tbody').html(str);
					}
				});
		    });
		    // 开票状态
		    $('.invoice-status').click(function(){
		    	var $this = $(this);
		    	query($this);
		    });
		    function query($this){
				if (!$this.hasClass('open')) {
		    		$this.addClass('open');
		    		$this.find('.body-all').show();
		    	}else{
		    		$this.removeClass('open');
		    		$this.find('.body-all').hide();
		    	};
		    }
		});
	</script>
</head>
<body>
<div class="head">
	@include('common.user_head')
</div>
<div class="user-head">
	<div class="main">
		<div class="logo">
			<a href="/"><img src="/resource/img/logo.png" alt=""></a>
			<div>我的钢链网
				<a href="/">返回首页</a>
			</div>
		</div>
	</div>
</div>	
<div class="user main">
	@include('common.user_menu')
	<div class="user-cont">
		<div class="invoice">
			<div class="title">发票查询</div>
			<div class="form">
				<form action="/select_invoice" method="post"  >
					<div class="form-group">
						<label for="">下单时间：</label>
						@if(!empty($start_time) && !empty($end_time))
						<input type="hidden" id="start_time" value="{{$start_time}}">
						<input type="hidden" id="end_time" value="{{$end_time}}">
						@endif
						<input type="text" class="form-control" id="dpd1" name="start_time" >
						<div class="to"></div>
						<input type="text" class="form-control" id="dpd2" name="end_time" >
					</div>
					<div class="form-group">
						<input type="submit" value="查询" class="btn-query">
					</div>
					<div class="right all-company">
						<div class="head-info">全部公司抬头</div>
						<i></i>
						<div class="body-all">
							<ul>
								<li class="active"><a href="javascript:;">全部公司抬头</a></li>
								@foreach($title as $key =>$title1)

								<li><a href="javascript:;">{{$title1->title}}</a></li>
								@endforeach
							</ul>
						</div>
					</div>
					<div class="clear"></div>
				</form>
			</div>
			<div class="table">
				<table>
					<thead>
						<tr>
							<th width="180px">订单号</th>
							<th width="180px">开票抬头</th>
							<th width="120px">申请时间</th>
							<th width="130px">开票金额（元）</th>
							<th width="120px">下单时间</th>
							<th width="">
								发票状态
								<div class="invoice-status">
									<div class="head-info">全部</div>
									<i></i>
									<div class="body-all">
										<ul>
											<li class="active"><a href="javascript:;">全部</a></li>
											<li rel="2"><a href="javascript:;">已开票</a></li>
											<li rel="1"><a href="javascript:;">开票中</a></li>
											<li rel="0"><a href="javascript:;">未开票</a></li>
										</ul>
									</div>
								</div>
							</th>
						</tr>
					</thead>
					<tbody>
					@foreach($data as $key => $data1)
						<tr>
							<td><div>{{$data1->order_sn}}</div></td>
							<td><div>{{$data1->title}}</div></td>
							<td><div>@if(!empty($data1->created)){{date("Y-m-d", $data1->created)}}@endif</div></td>
							<td><div>{{$data1->amount}}</div></td>
							<td><div>{{date("Y-m-d", $data1->order_time)}}</div></td>
							<td>
								@if($data1->status == 0)
									<div class="invoice-no"><div class="left">未开票</div><a href="javascript:;" class="billing" order_id="{{$data1->order_id}}" >立即开票</a></div>
								@elseif($data1->status ==1)
									<div class="invoice-in">开票中</div>
								@elseif($data1->status == 2)
									<div class="invoice-yes">已开票</div>
								@endif
								<!-- <div class="invoice-yes">已开票</div> -->
								<!-- <div class="invoice-in">开票中</div> -->
									<!--<div class="invoice-no"><div class="left">未开票</div><a href="javascript:;" class="billing">立即开票</a></div> -->
							</td>
						</tr>
					@endforeach
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<!-- 立即开票弹窗 -->
<div class="popup"></div>
<div class="popup-billing">
	<form action="">
		<div class="title">
			填写发票信息
			<div class="close"></div>
		</div>
		<div class="form">
			<div class="form-group">
				<label for="">公司抬头：</label>
				<input type="text" class="form-control">
			</div>
			<div class="form-group">
				<label for="">邮寄地址：</label>
				<input type="text" class="form-control">
			</div>
			<div class="form-group">
				<label for="">联 系 人：</label>
				<input type="text" class="form-control">
			</div>
			<div class="form-group">
				<label for="">联系电话：</label>
				<input type="text" class="form-control">
			</div>
			<input type="button" class="btn-billing" value="确认开票">
		</div>
	</form>
</div>
@include('common.shop_foot')
</body>
</html>